<?php

//防止恶意调用
if (!defined('IN_MOD'))
{
    die('Hacking attempt');
}

$type = moduleaqvarval("type","string");

$user              = cmf_get_current_user();
$this->assign($user);

$modulehook = "api";$hookname = "pay";require(MODULEPARA_PATH . 'config/modulehook.php');// 调用系统提示钩子

// 订单详情
if($type == "detail")
{
	$configinfo['module'][109]['author'] = "member/user_order_detail";
	
	$order_id = moduleaqvarval("order_id","intval");
	
	// 当前订单
	$modulewhere=array();
	$modulewhere["tablename"]="fastxcms_portal_post_order";
	$modulewhere["dataid"]=$configmember['id'];
	$modulewhere["dataidname"]="user_id";
	$modulewhere["where"]="id = '".$order_id."'";
	$orderinfo=modulepara("datainfo",$modulewhere);
	$parainfo = getmoduleparameter($orderinfo['id'],$configinfo['moduleid']);
	if(!empty($parainfo))
	{
		$orderinfo += $parainfo;
	}
	
	// 当前订单店铺信息
	$shopbase = getplatshopbaseinfo($orderinfo['supplier_id']);
	$orderinfo['shopid'] = $shopbase['shopid'];
	$orderinfo['shop_name'] = $shopbase['shop_name'];
	$orderinfo['shop_url'] = $shopbase['shop_url'];
	
	// 订单状态
	$orderstatus = "orderstatus";
	if($orderinfo[$orderstatus] == 5)
	{
		$orderinfo['orderstatus'] = "<font color='red'>已取消</font>";
	}else if($orderinfo[$orderstatus] == 3)
	{
		$orderinfo['orderstatus'] = "<font color='red'>已完成</font>";
	}else if($orderinfo[$orderstatus] == 2)
	{
		$orderinfo['orderstatus'] = "已付款，已发货";
	}else if($orderinfo[$orderstatus] == 1)
	{
		$orderinfo['orderstatus'] = "已付款，待发货";	
	}else{
		$orderinfo['orderstatus'] = "未付款，未发货";		
	}
	
	$this->smarty_assign('orderinfo',     $orderinfo);
	
	// 订单商品
	$modulewhere=array();
	$modulewhere["tablename"]="modulepara_order_goods";
	$modulewhere["arrayclass"]=$order_id;
	$modulewhere["bigclassname"]="orderid";
	$modulewhere["where"]='userid = "'.$configmember['id'].'"';
	$modulewhere["order"]='default';
	$ordergoodslist=modulepara("configmodule",$modulewhere,1);
	foreach($ordergoodslist as $key=>$val)
	{
		$goods_attr = getstrtoarr(",",$val['goods_attr']);
		foreach($goods_attr as $k=>$v)
		{
			$pinfo = getstrtoarr("-",$v);
			$ordergoodslist[$key]["goods_attr_arr"][$pinfo[0]] = $pinfo[1];
		}
	}
	$this->smarty_assign('ordergoodslist',     $ordergoodslist);
	
	// 支付方式HTML
	$payhtml = apipayhtml($orderinfo['payid'],$orderinfo['id']);		
	$this->smarty_assign('payhtml',     $payhtml);	
}else{
	
	// 条件筛选
	$where = "";
	$status = moduleaqvarval("status", "intval");
	if($status > 0)
	{
		$status = $status - 1;
		$where .= " and `orderstatus` = '$status'";
	}
	
	// 订单列表
	$orderstatus = "orderstatus";
	$modulewhere=array();
	$modulewhere["arrayclass"]=109;
	$modulewhere["where"]='user_id = "'.$configmember['id'].'"'.$where;
	$modulewhere["order"]='id desc';
	$orderlist=modulepara("configmodule",$modulewhere,1);
	foreach($orderlist as $key=>$val)
	{
		// 店铺信息
		$shopbase = getplatshopbaseinfo($val['supplier_id']);
		$orderlist[$key]['shop_name'] = $shopbase['shop_name'];
		$orderlist[$key]['shop_url'] = $shopbase['shop_url'];
		
		// 订单状态
		if($val[$orderstatus] == 5)
		{
			$orderlist[$key]['orderstatus'] = "<font color='red'>已取消</font>";
		}else if($val[$orderstatus] == 3)
		{
			$orderlist[$key]['orderstatus'] = "<font color='red'>已完成</font>";
		}else if($val[$orderstatus] == 2)
		{
			$orderlist[$key]['orderstatus'] = "已付款,已发货";
		}else if($val[$orderstatus] == 1)
		{
			$orderlist[$key]['orderstatus'] = "已付款,待发货";	
		}else{
			$orderlist[$key]['orderstatus'] = "未付款,未发货";		
		}
		
		// 订单商品
		$modulewhere=array();
		$modulewhere["tablename"]="modulepara_order_goods";
		$modulewhere["arrayclass"]=$val['id'];
		$modulewhere["bigclassname"]="orderid";
		$modulewhere["where"]='userid = "'.$configmember['id'].'"';
		$modulewhere["order"]='default';
		$ordergoodslist=modulepara("configmodule",$modulewhere,1);
		foreach($ordergoodslist as $key2=>$val2)
		{
			$goods_attr = getstrtoarr(",",$val2['goods_attr']);
			foreach($goods_attr as $k=>$v)
			{
				$pinfo = getstrtoarr("-",$v);
				$ordergoodslist[$key2]["goods_attr_arr"][$pinfo[0]] = $pinfo[1];
			}
		}
		$orderlist[$key]['ordergoodslist'] = $ordergoodslist;
	}
	$this->smarty_assign('orderlist',     $orderlist);	
}
?>